<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link rel="stylesheet" href="/static/login/login.css">
    <script>if (window.top !== window.self) {
        window.top.location = window.location;
    }</script>
</head>
<body>
<div class="main">
    <div class="login_1"></div>
    <div class="login_2"></div>
    <div class="middle">
        <div class="login_3"></div>
        <div class="mf">
            <div><input type="text" id="username" class="txt" placeholder="用户名" autocomplete="off"></div>
            <div><input type="password" id="pwd" class="txt" placeholder="口令"></div>
            <div><input type="button" value="登录" id="submit" class="btn"></div>
        </div>
        <div class="login_4"></div>
        <div style="clear: both"></div>
    </div>
    <div class="login_5"></div>
</div>
</body>
<script type="text/javascript" src="/static/hplus/js/jquery.min.js?v={php}echo time(){/php}"></script>
<script type="text/javascript" src="/static/layer/layer.js?v={php}echo time(){/php}"></script>
<script type="text/javascript" src="/static/cryptojs/cryptojs-aes.min.js?v={php}echo time(){/php}"></script>
<script type="text/javascript" src="/static/cryptojs/cryptojs-aes-format2.js?v={php}echo time(){/php}"></script>
<script type="text/javascript">
    $(function () {
        $(document).keydown(function (e) {
            if (e.keyCode === 13) {
                $('#submit').click();
            }
        });
        $('#username').focus()
        $('#submit').click(function () {
            let $this = $(this)
            let username = $('#username'), pwd = $('#pwd');
            if (username.val() === '') {
                layer.msg('登录用户名不能为空', {icon: 2, time: 1500}, function () {
                    username.focus();
                    return false;
                });
            } else if (pwd.val() === '') {
                layer.msg('登录密码不能为空', {icon: 2, time: 1500}, function () {
                    pwd.focus();
                    return false;
                });
            } else if (parseInt($this.data('doing')) !== 1) {
                let $pwd = CryptoJSAesJsonT.encrypt(pwd.val(), '{$salt}', '{$iv}');
                let $tc = null
                $.ajax({
                    type: 'post', dataType: 'json', cache: false,
                    url: '/login/dologin',
                    data: {'username': username.val(), 'pwd': $pwd},
                    beforeSend: function () {
                        $tc = layer.load(2, {shade: [0.3, '#fff']})
                        $this.attr('data-doing', 1)
                    },
                    success: function (msg) {
                        $this.attr('data-doing', 0)
                        layer.close($tc)
                        if (msg.code === 200) {
                            layer.msg(msg.message, {icon: 1, time: 1000}, function () {
                                location.href = '/';
                            });
                        } else {
                            layer.msg(msg.message, {icon: 2, time: 1500});
                        }
                    },
                    error: function (msg) {
                        console.log(msg)
                    }
                });
            }
        });
    });
</script>
</html>
